const userModel = require("../../models/userModel")

const userService = {
    login: async ({ username, password }) => {
        return userModel.find({
            username,
            password
        })

    },

    upload: async ({ _id, username, introduction, gender, avatar }) => {
        if (avatar) {
            return userModel.updateOne({
                _id
            }, {
                username, introduction, gender, avatar
            })
        } else {
            return userModel.updateOne({
                _id
            }, {
                username, introduction, gender
            })
        }
    },
    add: async ({ username, introduction, gender, role, avatar, password }) => {
        console.log(username, introduction, gender, role, avatar, password)
        return userModel.create({
            username, introduction, gender, role, avatar, password
        })
    },
    getList: async ({ id }) => {
        return id ? userModel.find({ _id: id }, ['username', 'role', 'password', 'introduction']) : userModel.find({}, ['username', 'role', 'avatar', 'introduction', 'gender'])
    },
    delList: async ({ _id }) => {
        return userModel.deleteOne({ _id })
    },

    putList: async (body) => {
        return userModel.updateOne({ _id: body._id }, body)
    }
}

module.exports = userService